/* -+- file  ./kf2/Events/MessageEvent.cs -+- */
/*
 * kf2 jabber client
 * ~~~~~~~~~~~~~~~~~
 *
 * Copyright (C) 2006-2007 Przemysław Sitek
 * 				<przemyslaw.sitek at wp.pl> 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

using System;
using Habazie.kf2.Core;
using Habazie.kf2.Net;
using Habazie.kf2.GUI;

namespace Habazie.kf2.Events
{
	
	public class MessageEvent : Event
	{
		private jabber.protocol.client.Message m_Message;
		
		public MessageEvent(Account source, jabber.protocol.client.Message msg)
			: base (source, msg)
		{
			m_Message = msg;
			m_EventName = "msg";

			Util.PlaySound ("message-in");
		}
		

		
		
		///<summary>Display this event</summary>
		public override void Display ()
		{
			MessageWindow win = new MessageWindow ();
			win.Msg = m_Message;
			win.Show ();
		}
		
		///<summary>Notify user of event</summary>
		public override void Notify (INotifyService notify)
		{
			string header;
			if (this.SourceItem != null)
				header = this.SourceItem.Name;
			else
				header = m_Message.From.ToString ();
				
			if (m_Message.Body != null)
				notify.Notify (NotifyClass.Message, header, m_Message.Body);
		}
		
		
		///<summary>Get string representation of this event</summary>
		public override string ToString ()
		{
			return m_Message.From.ToString ();
		}
	}
}
